very easy, the trick is access to the class changeHistoryManager.

Try this example in the “Adaptavist Scriptrunner” Script Console view. Just put the ID of the ticket and run the code. You will see always the last change of the issue.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager

IssueManager issueManager = ComponentAccessor.getIssueManager();
def issue = issueManager.getIssueObject("JIRA-1234");
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getAllChangeItems(issue)

if (changeItems?.size() > 0) {
    def userUtil = ComponentAccessor.getUserUtil()
    def last_change = changeItems.sort(false).last()
    def text = "LAST MODIFIED FIELD:"+ last_change["field"]+ "; FROM VALUE:"+ last_change["fromValue"] + "; TO VALUE:"+ last_change["toValue"]
    return text;
} else {
     return "NO CHANGES"
}
.'s avatar
Posted by:.

One thought on “Groovy Script for JIRA to detect the last field change of a ticket

  1. In Jira 9 the line 12 of the code must be like this:

    def text = "LAST MODIFIED FIELD:"+ last_change["field"]+ "; FROM VALUE:"+ last_change["fromValues"] + "; TO VALUE:"+ last_change["toValues"]
    

    NOTE the last “s” in fromValues and toValues

    Like

Leave a comment